﻿using System;
using UnityEngine.Rendering;

namespace UnityEngine.PostProcessing
{
	// Token: 0x020000C1 RID: 193
	public sealed class FogComponent : PostProcessingComponentCommandBuffer<FogModel>
	{
		// Token: 0x17000074 RID: 116
		// (get) Token: 0x060005A0 RID: 1440 RVA: 0x00021F70 File Offset: 0x00020170
		public override bool active
		{
			get
			{
				return base.model.enabled && this.context.isGBufferAvailable && !this.context.interrupted;
			}
		}

		// Token: 0x060005A1 RID: 1441 RVA: 0x00021FA4 File Offset: 0x000201A4
		public override string GetName()
		{
			return "Fog";
		}

		// Token: 0x060005A2 RID: 1442 RVA: 0x00021FAC File Offset: 0x000201AC
		public override DepthTextureMode GetCameraFlags()
		{
			return DepthTextureMode.Depth;
		}

		// Token: 0x060005A3 RID: 1443 RVA: 0x00021FB0 File Offset: 0x000201B0
		public override CameraEvent GetCameraEvent()
		{
			return CameraEvent.BeforeImageEffectsOpaque;
		}

		// Token: 0x060005A4 RID: 1444 RVA: 0x00021FB4 File Offset: 0x000201B4
		public override void Init(PostProcessingContext pcontext, FogModel pmodel)
		{
			base.Init(pcontext, pmodel);
			FogModel.Settings settings = base.model.settings;
			RenderSettings.fog = base.model.enabled;
			RenderSettings.fogColor = settings.color;
			RenderSettings.fogMode = settings.mode;
			RenderSettings.fogDensity = settings.density;
			RenderSettings.fogStartDistance = settings.start;
			RenderSettings.fogEndDistance = settings.end;
		}

		// Token: 0x060005A5 RID: 1445 RVA: 0x00022024 File Offset: 0x00020224
		public override void PopulateCommandBuffer(CommandBuffer cb)
		{
			FogModel.Settings settings = base.model.settings;
			Material material = this.context.materialFactory.Get("Hidden/Post FX/Fog");
			material.shaderKeywords = null;
			material.SetColor(FogComponent.Uniforms._FogColor, settings.color);
			material.SetFloat(FogComponent.Uniforms._Density, settings.density);
			material.SetFloat(FogComponent.Uniforms._Start, settings.start);
			material.SetFloat(FogComponent.Uniforms._End, settings.end);
			FogMode mode = settings.mode;
			if (mode != FogMode.Linear)
			{
				if (mode != FogMode.Exponential)
				{
					if (mode == FogMode.ExponentialSquared)
					{
						material.EnableKeyword("FOG_EXP2");
					}
				}
				else
				{
					material.EnableKeyword("FOG_EXP");
				}
			}
			else
			{
				material.EnableKeyword("FOG_LINEAR");
			}
			RenderTextureFormat format = (!this.context.isHdr) ? RenderTextureFormat.Default : RenderTextureFormat.DefaultHDR;
			cb.GetTemporaryRT(FogComponent.Uniforms._TempRT, this.context.width, this.context.height, 24, FilterMode.Bilinear, format);
			cb.Blit(BuiltinRenderTextureType.CameraTarget, FogComponent.Uniforms._TempRT);
			cb.Blit(FogComponent.Uniforms._TempRT, BuiltinRenderTextureType.CameraTarget, material, (!settings.excludeSkybox) ? 0 : 1);
			cb.ReleaseTemporaryRT(FogComponent.Uniforms._TempRT);
		}

		// Token: 0x040004C4 RID: 1220
		private const string k_ShaderString = "Hidden/Post FX/Fog";

		// Token: 0x020000C2 RID: 194
		private static class Uniforms
		{
			// Token: 0x040004C5 RID: 1221
			internal static readonly int _FogColor = Shader.PropertyToID("_FogColor");

			// Token: 0x040004C6 RID: 1222
			internal static readonly int _Density = Shader.PropertyToID("_Density");

			// Token: 0x040004C7 RID: 1223
			internal static readonly int _Start = Shader.PropertyToID("_Start");

			// Token: 0x040004C8 RID: 1224
			internal static readonly int _End = Shader.PropertyToID("_End");

			// Token: 0x040004C9 RID: 1225
			internal static readonly int _TempRT = Shader.PropertyToID("_TempRT");
		}
	}
}
